#include "event_poller.h"
#include "thread_pool-inl.h"
#include <iostream>
#include "task_executor-inl.h"
using namespace std;
std::atomic<int> val;

void test_tast()
{
	auto ptr = singleton<thread_pool<event_epoller>>::Instance();
	using timer = std::chrono::system_clock;
	auto start = timer::now();
	for (int i = 0; i < 1000 * 10000; i++)
	{

		ptr->get_poller<round_robin>(false).async([start]() {
			if (++val == 1000 * 10000) {
				auto end = timer::now();
				auto time_span = std::chrono::duration_cast<std::chrono::duration<double>>(end - start);
				cout << "ss: " << time_span.count() << endl;
			}
		});
	}
	cout << "has completed put" << endl;
	cin.get();
}

void test_timer()
{
	event_epoller ptr;
	ptr.start();
	auto now = std::chrono::system_clock::now();
	std::time_t tt = std::chrono::system_clock::to_time_t(now);
	std::cout << "now is: " << ctime(&tt) << std::endl;
	ptr.run_after(1000, false, [&]() {
		auto now = std::chrono::system_clock::now();
		std::time_t tt = std::chrono::system_clock::to_time_t(now);
		std::cout << "1 seconds is: " << ctime(&tt) << std::endl;
		});

	ptr.run_after(2000, false, [&]() {
		auto now = std::chrono::system_clock::now();
		std::time_t tt = std::chrono::system_clock::to_time_t(now);
		std::cout << "2 seconds is: " << ctime(&tt) << std::endl;
		});

	ptr.run_after(3000, false, [&]() {
		auto now = std::chrono::system_clock::now();
		std::time_t tt = std::chrono::system_clock::to_time_t(now);
		std::cout << "3 seconds is: " << ctime(&tt) << std::endl;
		});
}
int main()
{
	test_tast();
	return 0;
}
